package com.iceland.client.client.proxy;
import com.iceland.client.client.Client;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

public class ProxyClient extends Client {

    private String remoteHost;
    private int port;

    public void setRemoteHost(String remoteHost) {
        this.remoteHost = remoteHost;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public ProxyClient(String remoteHost, int port) {
        super(2, NioSocketChannel.class);
        this.remoteHost=remoteHost;
        this.port=port;
    }

    @Override
    protected void preStart(Bootstrap bs) {
        bs.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast( new ProxyHandler());
            }
        });
    }


    @Override
    protected void afterStart() {

    }

    public synchronized ChannelFuture connectServer(){
        return bs.connect(remoteHost, port);
    }

    public String getRemoteHost() {
        return remoteHost;
    }

    public int getPort() {
        return port;
    }

}
